<template>
	<view class="page">
			<view class="searchBox">
				<view class="inputBox">
					<view class="inputRow">
						<view class="label">
							{{language.consumeRecord.label1}}:
						</view>
						<view :class="params.attendDate_begin ? 'val' : 'emty'" @click="attendDate_beginShow=true">
							{{params.attendDate_begin ? params.attendDate_begin : language.consumeRecord.tip }}
						</view>
					</view>
					<view class="inputRow">
							<view class="label">
								{{language.consumeRecord.label2}}:
							</view>
							<view :class="params.attendDate_end ? 'val' : 'emty'" @click="attendDate_endShow=true">
								{{params.attendDate_end ? params.attendDate_end : language.consumeRecord.tip }}
							</view>
					</view>
				</view>
				<view class="btnBox">
					<view class="btn"  @click="goSearch">
						{{language.consumeRecord.search}}
					</view>
				</view>
			</view>
			<u-subsection :list="selectList" :current="current"  @change="sectionChange"></u-subsection>
			<scrollYBox styleText="height: calc( 100vh - 0rpx ) ;" @scrolltolower="scrolltolower" :list="list">
						<template>
							<view style="padding-bottom: 50rpx;">
								<view class="boxItem" v-for="(item,index) in list" :key="index">
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{'科目订单：'}}
											</view>
											<view class="val">
												{{item.courseName }}
											</view>
										</view>
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{'上课日期：'}}
											</view>
											<view class="val">
												{{item.attendDate }}
											</view>
										</view>
										<view class="btn" style="background: #f5bd00;" v-if="!current" @click="handleDetail(item.id)">
											{{'申请退课'}}
										</view>
									</view>
									<view class="row flex">
										
									</view>
								</view>
							</view>
						</template>
			</scrollYBox>
			<u-datetime-picker
			    :show="attendDate_beginShow" ref="datetimePicker" v-model="attendDate_begin" 
			    mode="date"  @cancel="attendDate_beginShow=false" @confirm="attendDate_beginConfirm"
			       ></u-datetime-picker>
			<u-datetime-picker
				:show="attendDate_endShow" ref="datetimePicker" v-model="attendDate_end" 
				mode="date"  @cancel="attendDate_endShow=false" @confirm="attendDate_endConfirm"
			   ></u-datetime-picker>
	</view>
</template>

<script>
	import { csSubjectOrderListApi,csSubjectOrderApplyForUnsubApi} from '@/common/api/commonApi/bugClass.js'
	export default {
		data() {
			return {
				list:[],
				params:{
					pageNo:1,
					pageSize: 10,
				},
				attendDate_begin: Number(new Date()),
				attendDate_end: Number(new Date()),
				attendDate_beginShow : false,
				attendDate_endShow : false,
				total : 0,
				isTeacher: uni.getStorageSync('isTeacher') ? uni.getStorageSync('isTeacher') : 2,
				auditObj:{},
				auditShow: false,
				auditList: [{
						name: '是',
						value: 1
					},
					{
						name: '否',
						value: 2,
					},
				],
				auditValue: 1,
				auditOpinion:'',
				selectList:[
					'正常',
					'待审批',
					'已退订',
				],
				current:0,
			}
		},
		components:{
		},
		methods: {
			sectionChange(index){
				this.current = index
				this.goSearch()
			},
			attendDate_beginConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.attendDate_begin = date
				console.log(this.params.attendDate_begin);
				this.attendDate_beginShow = false
			},
			attendDate_endConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.attendDate_end = date
				this.attendDate_endShow = false
			},
			handleDetail(id){
				uni.showModal({
					content:'是否确认退课',
					success: (res) => {
						if(res.confirm){
							csSubjectOrderApplyForUnsubApi({
								id
							}).then(res=>{
								this.setMessage('操作成功')
								setTimeout(()=>{
									this.goSearch()
								},500)
							})
						}
					}
				})
			},
			scrolltolower(){
				if(this.total == this.list.length){
					return this.setMessage('没有更多了')
				}
				this.params.pageNo ++
				this.getList()
			},
			goSearch(){
				if(this.params.attendDate_begin && this.params.attendDate_end ){
					if(new Date(this.params.attendDate_begin) > new Date(this.params.attendDate_end) ) return this.setMessage('开始时间不能大于结束时间')
				}
				this.params.pageNo = 1 
				this.getList()
			},
			getList(){
				let params = this.params
				if(!params.attendDate_end) delete params.attendDate_end
				if(!params.attendDate_begin) delete params.attendDate_begin
				// if(this.isTeacher==1)
				 params.status = this.current + 1
				return csSubjectOrderListApi(params).then(res=>{
					if(params.pageNo==1) this.list = []
					this.list = this.list.concat(res.result.records)
					this.total = res.result.total
				})
			},
			goSearch(){
				this.params.pageNo = 1
				this.getList()
			}
			
		},
		onLoad() {
			this.goSearch()
			// this.setPageTitle(this.language.leaveRecord.title)
			// this.selectList[0] = this.language.leaveRecord.selectType1
			// this.selectList[1] = this.language.leaveRecord.selectType2
			// this.selectList[2] = this.language.leaveRecord.selectType3
			// this.selectList[3] = this.language.leaveRecord.selectType4
		},
		onShow() {
		},
	}
</script>

<style lang="scss" scoped>
	.searchRow{
			background-color: #fff;
			display: flex;
			align-items: center;
			padding: 0rpx 20rpx 0 20rpx;
			border-bottom: 2rpx solid #dedede;
			height: 140rpx;
			margin: 20rpx;
			.leftBox{
				flex: 1;
				.row{
					display: flex;
					align-items: center;
					height: 70rpx;
					padding-left: 20rpx;
					.label{
						color: #000000d9;
						margin-right: 30rpx;
					}
					.val{
						color: #595959;
					}
				}
			}
			.btn{
				width: 140rpx;
				height: 56rpx;
				border-radius: 10rpx;
				color: #fff;
				@include flexCenter;
				background-color: #4089f0;
			}
			
	}
	
	
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 0 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			flex: 1;
			padding-right: 30rpx;
			.inputRow{
				height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 20rpx;
				.label{
					color: #191919;
					margin-right: 30rpx;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					// padding-left: 10rpx;
					// width: 50%;
					flex: 1;
					display: flex;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
				}
				.btn{
						padding: 0 30rpx;
						// width: 120rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
						margin-right: 10rpx;
				}
			}
		}
		
}
</style>
